/**
 * @param {number[]} nums
 * @return {number}
 */
var countTriplets = function (nums) {
  /**
    * 
    * 
    *  let count = 0
          for(let i=0;i<nums.length;i++){
              for(let j=0;j<nums.length;j++){
                for(let k=0;k<nums.length;k++){
                  if((nums[i]&nums[j]&nums[k])==0) count++
                }
              }
          }
      return count
    * 
    */
  let cnt = new Array(1 << 16).fill(0)
  for (x of nums) {
    for (y of nums) {
      ++cnt[x & y]
    }
  }

  let ans = 0
  for (k of nums) {
    for (let i = 0; i < 1 << 16; i++) {
      if ((i & k) == 0) {
        ans += cnt[i]
      }
    }
  }


  return ans
}

countTriplets([2, 1, 3])
